#!/usr/bin/env ruby

#You might want to change this
ENV["RAILS_ENV"] ||= "development"

require File.dirname(__FILE__) + "/../../config/environment"

$running = true;
Signal.trap("TERM") do
  $running = false
end

require  File.dirname(__FILE__) + "/../../app/models/feed"

while($running) do

  ActiveRecord::Base.logger.info("start to grab")
  Feed.find(:all).each do |feed|
    begin
      feed.refresh
    rescue
      puts $!
    end
  end
  ActiveRecord::Base.logger.info("grabbing finished")
  sleep 10
end
